/*
	Copyright (C) 2009 Salil Bhagurkar
	
	This file is part of ViSE
	
	ViSE is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	ViSE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with ViSE.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _VISE_H_
#define _VISE_H_


//ViSE data node
#define TYPE_VDATA 8
//Keep servicing this node
#define TYPE_VDATA_LOOP 16
//Don't take data from my referrer
#define TYPE_VDATA_NO_INCOMING 32
//Don't give data to my clients, just service them
#define TYPE_VDATA_NO_OUTGOING 64

//Type of referrer's link to us
#define REFER_SERVER 0
#define REFER_CLIENT 1

//Builtin interface nodes.
#define TYPE_VDATA_BUILTINSMASK 255 << 8
#define TYPE_VDATA_SELECT 1 << 8 //String select is just a node with TYPE_VDATA_SELECT
#define TYPE_VDATA_FSIF 2 << 8
#define TYPE_VDATA_CMDLINE 3 << 8
#define TYPE_VDATA_MATHVM 4 << 8 //Instructions to the math vm
#define TYPE_VDATA_FSENUM 5 << 8 //Enumerates entries at a location in the fsif


/*The generic node structure that holds data*/
struct node {
	u16 type;
	char name[FS_NAME_LEN];
	struct node *server;
	u8 data_type;
	u32 count; //'count' number of items of type 'type'
	void *data;
	u32 nr_clients;
	struct node *client[];
};

struct cmdline {
	u16 type;
	char name[FS_NAME_LEN];
	int cur_no; //The current commandline parameter number that WILL be read.s
	char *input; //This points to the current string from which parameters are being read
};

struct select {
	u16 type;
	char name[FS_NAME_LEN];
	struct node *server;
	u32 nr_clients;
	struct node *client[];
};


struct mathvm {
	u16 type;
	char name[FS_NAME_LEN];
	u32 count;
	void *stream;
	u32 nr_clients;
	struct node *client[];
};

//FS interface builtin
struct fsif {
	u16 type;
	char name[FS_NAME_LEN];
	struct node_fs *fs; //Current position
};

/*Enumerates directory entries. Reading from this will result in the names of the files coming one
by one.*/
struct fsenum {
	u16 type;
	char name[FS_NAME_LEN];
};


#define NR_DATA_TYPES 7

enum {DATA_TYPE_VOID, DATA_TYPE_CHAR, DATA_TYPE_BYTE, DATA_TYPE_WORD, DATA_TYPE_DWORD, DATA_TYPE_QWORD, DATA_TYPE_INT};


extern u32 data_type_size[];

struct node *create_node(u16 type, u8 data_type, u32 count, char *name, int nr_clients);
struct node *create_mapped_node(struct node *n, char *name, int nr_clients);

void service(struct node *node, struct node *referrer, int code);
struct node *fs_cast(char *name);

#define GET_INT(n) ((u32)*((u32 *)n->data))

//Set this to make ViSE puke a lot of messages
//#define DEBUG_EXECUTION

#endif
